package com.tibbytang.opengllearn.main

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.AppCompatTextView
import androidx.recyclerview.widget.RecyclerView
import com.tibbytang.opengllearn.R
import me.drakeet.multitype.ItemViewBinder

class OpenGLItemViewBinder(val onItemClickListener: OnItemClickListener) :
    ItemViewBinder<String, OpenGLItemViewBinder.ViewHolder>() {
    override fun onCreateViewHolder(inflater: LayoutInflater, parent: ViewGroup): ViewHolder {
        return ViewHolder(inflater.inflate(R.layout.item_opengl, parent, false))
    }

    override fun onBindViewHolder(p0: ViewHolder, p1: String) {
        p0.nameText.text = p1
        p0.nameText.setOnClickListener {
            onItemClickListener.onItemClick(p0.adapterPosition)
        }
    }

    inner class ViewHolder(itemview: View) : RecyclerView.ViewHolder(itemview) {
        val nameText = itemview.findViewById<AppCompatTextView>(R.id.name_view)
    }

    interface OnItemClickListener {

        fun onItemClick(position: Int)
    }
}